
from whiff.middleware import misc
import os

class whiffText(misc.utility):
    def __init__(self, page):
        self.page = page
    def __call__(self, env, start_response):
        path = self.param_value(self.page, env).strip()
        if path.find('..')>=0 or path.find('//')>=0:
            raise ValueError, "sorry '..' and '//' not allowed "+repr(path)
        if not path.startswith("./"):
            raise ValueError, "path must start './'"
        path = path[2:]
        [directory, myfile] = os.path.split(__file__)
        fullpath = os.path.join(directory, path)+".whiff"
        #pr "joined", (directory, path, fullpath)
        txt = open(fullpath).read()
        start_response("200 OK", [('Content-Type', 'text/plain')])
        return [txt]

__middleware__ = whiffText
